import React from 'react';
import { TInputProps } from './Types';
import { convert, bs } from './convert';
import { StyleProp, TextInput, TextStyle } from 'react-native';
import { transFont } from './Texts';

export function Input({ ...props }: TInputProps) {
  if (props.p === undefined) props.p = 0;
  const cStyle = bs(props);
  const keys = Object.keys(props);
  if (props.phr && keys.indexOf('phr') > keys.indexOf('placeholder')) {
    props.placeholder = props.phr;
    delete props.phr;
  }
  if (props.phc && keys.indexOf('phc') > keys.indexOf('placeholderTextColor')) {
    props.placeholderTextColor = props.phc;
    delete props.phc;
  }
  const { c = 'white', ff = 'Inter', fw = '500', fs = 16, lh } = props;
  const fStyle: StyleProp<TextStyle> = {
    color: c,
    fontFamily: transFont(ff, fw),
    fontWeight: fw,
    fontSize: convert(fs),
    lineHeight: convert(lh),
    textAlign: props.ta,
  };
  return (
    <TextInput
      numberOfLines={+(props.nol ?? 1)}
      defaultValue={props.dv}
      {...props}
      style={[cStyle, fStyle, props.style]}
      ref={props.inputRef}
    />
  );
}
